package com.ruoyi.web.controller.calendar;

import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.*;
import com.ruoyi.common.core.text.CharsetKit;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ICalendarService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: TODO
 * @Author: wangbo
 * @Since: 2022-08-01  16:43:08
 */
@RestController
@RequestMapping("/calendar/index")
public class IndexController extends BaseController {

    @Autowired
    private ICalendarService calendarService;
    /**
     * 获取菜单列表
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody CalendarVO calendarVO)
    {
        List<CalendarVO> calendarVOList = calendarService.selectConfigList(calendarVO);
        return AjaxResult.success(calendarVOList);
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody CalendarAddVO calendarAddVO)
    {
        return toAjax(calendarService.add(calendarAddVO));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody CalendarUpdateVO calendarUpdateVO)
    {
        return toAjax(calendarService.update(calendarUpdateVO));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") String id)
    {
        if (StringUtils.isBlank(id))
        {
            return AjaxResult.error("id不能为空");
        }
        return toAjax(calendarService.deleteById(id));
    }
}
